<template>
  <div class="detail-nav-bar">
    <nav-bar>
      <div slot="left" @click="backClick">
        <img src="~assets/img/common/back.svg" class="backImg" />
      </div>
      <div slot="center" class="center">
        <div
          v-for="(item, index) in titles"
          :key="index"
          @click="titleClick(index)"
          :class="{ 'center-item': currentIndex === index }"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar.vue";

export default {
  name: "DetailNavBar",
  data() {
    return {
      currentIndex: 0,
    };
  },
  components: { NavBar },
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  methods: {
    backClick() {
      this.$emit("backClick");
    },
    titleClick(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
  },
};
</script>

<style scoped>
.detail-nav-bar {
  position: relative;
  background-color: #fff;
  z-index: 2;
}
.center {
  display: flex;
  text-align: center;
  font-size: 14px;
  justify-content: space-between;
}
.center-item {
  color: var(--color-tint);
}
.backImg {
  width: 20px;
  margin-top: 12px;
}
</style>
